home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / pc_files / mktdata / econdata / docutils / pdgsup.exe / BANKER.DOC next >
Text File  |  1992-04-17  |  17KB  |  344 lines

  1.                 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  2.                 ▒                                            ▒
  3.                 ▒   BANKER (ver 1.01) :: The G-Bank Maker    ▒
  4.                 ▒                                            ▒
  5.                 ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  6.  
  7.  
  8. I.    What is BANKER?
  9. II.    How to use BANKER?
  10. III.How to format input data for BANKER?
  11. IV.    Notes for programmers
  12.  
  13. I.    What is BANKER?
  14.  
  15.     BANKER is a G data bank maker.  It creates G data banks without going 
  16. through G.  It is particularly suited for making large G data bank, since 
  17. BANKER-generated data bank is NOT bounded by the 2500 maximum number of
  18. series associated with any G-generated bank currently.  In other words,
  19. with BANKER, your G-bank can literally include millions of series, and 
  20. the size of your hard disk becomes the effective constraint.
  21.  
  22.      BANKER makes both hashed (.hbk, .hin) and compressed (.cbk, .cin) G 
  23. banks, however, users are strongly encouraged to produce the hashed bank, as 
  24. it is now the standard data bank I.E.R.F. regularly creates and maintains.
  25.  
  26.  
  27. II.  Usage:
  28.  
  29. Syntax:  BANKER [option] <data> [bank]
  30.  
  31. Options are one or more of the following option characters preceded by "-"
  32. or "/".  If no option specified, hashed bank will be produced.
  33.  
  34.   BANK TYPE OPTIONS           OTHER OPTIONS
  35.   -h hashed bank (default)    -b<###> issue number of BINs for hashed bank
  36.   -c compressed bank          -v      view series names while processing
  37.                               -d      debugging
  38.                               -l      look at the finished bank
  39.                               -t[XXX] take bank title
  40. Examples: 
  41. BANKER lift.dat              :produces default bank (LIFT.HBK, LIFT.HIN)
  42. BANKER -h lift.dat           :produces LIFT.HBK, LIFT.HIN
  43. BANKER -b101 lift.dat        :makes the hashed bank with # of BINs = 101
  44. BANKER -d lift.dat           :make hashed bank, debugging only
  45. BANKER -c lift.dat           :produces LIFT.CBK, LIFT.CIN
  46. BANKER -cv lift.dat          :and displays series names while processing
  47. BANKER -cvtinforum lift.dat  :and takes the bank_title as 'inforum'
  48. BANKER -ctinforum-d lift.dat :debugging, and bank_title = 'inforum'
  49. BANKER -cdtinforum lift.dat  :debugging, and bank_title = 'inforum'
  50. BANKER -cd lift.dat          :make compressed bank, debugging only
  51.  
  52.      Note that normally only the very first option switch is required to be
  53. preceded with '-' or '/'.  But there is a caveat with -t switch.  If it is 
  54. chosen and a bank title is attached next to it, then the next chosen option 
  55. must be preceded with '-' or '/', which would otherwise be optional.
  56. Beside, if your bank title consists of more than one word, connect these
  57. words with '+' so that there will not be any space in between the words.
  58. In light of this, you may decide to ignore -t switch altogether, in which 
  59. case you will be prompted to provide a bank title once BANKER starts
  60. running.  Yet another way to input the bank title is to bury it in brackets
  61. '{ }' and put it at the very beginning of your formatted data file.  In a
  62. way, brackets '{ }' indicate comments to BANKER.
  63.  
  64.      A file named BANKER.ERR will be automatically produced for each run of
  65. BANKER.  It contains information on data compression status on each series as
  66. well as some other related messages (if any).  The most commom message on 
  67. data compression includes:
  68.  
  69. (1) "Gave up compression xxx: difference larger than 32767 or all-zero series";
  70. (2) "Gave up compression xxx: difference larger than LONG_MAX"
  71.  
  72.     The first simply means a all-zero series has been encountered or the 
  73. largest first difference of all observations of this series is greater than
  74. 32767.   Note that if the observations have decimal places (floating-point
  75. number), the first difference is taken after all the decimal places have
  76. been slided to the rightmost.   This point may also help you understand the
  77. second message, in which case even though the largest first difference of 
  78. your data prior to decimal-point-sliding is no greater than LONG_MAX
  79. (2,147,483,647), after the "sliding" (especially those numbers have many
  80. decimal places), the largest first difference may well exceeds LONG_MAX.
  81.  
  82.  
  83. III.  How to format data file for BANKER 
  84.  
  85.      BANKER handles all conventional G DATA and MATDAT input formats,
  86. which are assumed to be known to the G user.  There are detailed discussion 
  87. in G "help" files and in the Appendix of Clopper Almon's "The Craft of 
  88. Economic Modeling".
  89.  
  90.      BANKER also accepts the INFORUM one-series-per-line format, which
  91. was initially developed to process very large data banks more efficiently, 
  92. such as the World Tables of Social and Economic Indicators.  The general
  93. idea of this format is to stock all the information about a series on one 
  94. line (record), including, of course, all its observations.  
  95.  
  96. Here is an example of the one-series-per-line format:
  97.  
  98.        ▒          gdp$  1985  Q  1  0  5025  5130.5  5.255e3  .. .. ▒ 
  99.        ▒                                                            ▒ 
  100.        ▒     where,                                                 ▒ 
  101.        ▒          gdp$ : series_name                                ▒ 
  102.        ▒          1985 : baseyear (can also be written as 85)       ▒ 
  103.        ▒             Q : frequency (M = Monthly, A = Annual)        ▒ 
  104.        ▒             1 : starting_period                            ▒ 
  105.        ▒             0 : decimal point left-shift factor            ▒ 
  106.        ▒          5025 : observation #1                             ▒ 
  107.        ▒        5130.5 : observation #2                             ▒ 
  108.        ▒       5.255e3 : observation #3                             ▒ 
  109.        ▒           ..  :  ..                                        ▒ 
  110.  
  111.  
  112.     All seems clear except, perhaps, the fifth item under this format -
  113. decimal point left-shift factor.  Thus some explanations (orjustifications 
  114. for it) are in order.  Simply put, this left-shift factor enables you to 
  115. manipulate (add) the decimal places in your data.  For example, some BLS 
  116. data often requires some additional decimal places, and this left-shift 
  117. factor can help you do just that.  If, on the other hand, there is no need 
  118. to modify decimal places in your data, use zero as the left-shift factor.
  119.  
  120.     Please take note that each item must be separated by at least one space 
  121. (as shown in the example above).
  122.  
  123.     It should be mentioned in passing that BANKER will keep intact the 
  124. series names exactly as in the formatted input file.  That is, if a 
  125. series name (or part of it) is in upper (lower) case, it will remain that 
  126. way in the bank created by BANKER.
  127.  
  128.  
  129. IV. Notes for programmers
  130.  
  131.      As indicated earlier, BANKER can make both hashed and compressed G 
  132. banks.  In the compressed bank, each series has its own starting date
  133. and number of observations and most series have been compressed. 
  134. Compression involves these steps:
  135.  
  136.     - find and record the number of decimal points in the series.       
  137.     - slide the decimal to the right until the series is all integers. 
  138.     - record the first observation as a 4-byte integer.
  139.     - record the first differences of the series as 2-byte integers. 
  140.     - if a series cannot be accurately recorded in this compressed
  141.       form, it is declared to have 255 decimal places (just a flag), and 
  142.       the observations recorded as four-byte floating point numbers.
  143.     - missing observations are marked with a special code.
  144.     - the data file has the extension "cbk"; and the index, "cin".
  145.  
  146.     The .cin file contains:
  147.  
  148.    item                  size in bytes  C type
  149.    ==============================================================
  150.    ns                    2              int
  151.    nc                    2              unsigned int
  152.    names                 nc             char
  153.  
  154.     Here ns is the number of series, and nc is the number of characters in 
  155. all the series names, counting the nulls at the end of each series name. 
  156. If there were three variables in the bank with names tom, dick, and harry, 
  157. ns would be 3, and the names vector would be
  158.  
  159.      tom0dick0harry0
  160.  
  161.     where 0 represents a null ('\0' in C), and nc would be 15, the number of 
  162. characters in the names vector, counting the nulls. 
  163.  
  164.    The .cbk file contains:
  165.    item                  size in bytes  C type
  166.    ==============================================================
  167.    title                 80             char
  168.    ns                    2              int
  169.    position              4              unsigned long
  170.    series 1              variable       see below
  171.    ....                                 ........
  172.    series n              variable       see below
  173.    indx                  4*ns           unsigned long
  174.  
  175.     Here, ns is again the number of series; indx is an array containing the 
  176. byte numbers in this file at which the series begin.  To continue the example, 
  177. suppose that the series "tom" requires 101 bytes, "dick" requires 121 bytes, 
  178. and "harry" requires 81.  Then "indx" is the vector (86, 187, 308).  (Remember 
  179. that in C a file starts with byte 0).  The "position" is the byte number at 
  180. which this "indx" array begins.  In the example, it will be 389.
  181.  
  182.     Each compressed series has the format:
  183.  
  184.    item                    size in bytes  C type
  185.    ==============================================================
  186.    BaseYear              1              unsigned char
  187.    FreqPeriod            1              unsigned char
  188.    SlashDecplaces        1              unsigned char
  189.    NDif                  2              int
  190.    FirstObs              4              long
  191.    Differences           2*NDif         int
  192.  
  193.    where
  194.      BaseYear = the year of the first observation, minus 1900.
  195.      FreqPeriod = 16*frequency+period, where
  196.        frequency is the number of observations per year (1, 4, or 12) 
  197.        period = period of first observation.  (For frequencies above 12, 
  198.        set FreqPeriod = 255.  This value signals that two integers have 
  199.        been inserted following this byte containing the frequency and the
  200.        period.)
  201.      SlashDecplaces = 16*SlashFactor + Number of Decimal places
  202.        (SlashFactor is normally 0; the Press program, however, allows the 
  203.        option of dividing by a power of 2 to reduce the magnitudes of a 
  204.        series so that it can be compressed.  The SlashFactor is the power 
  205.        (1, 2, 3, etc.) used on this series.  In Press, the default maximum 
  206.        slash factor is 0, so the occurrence of non-zero slash factors is   
  207.        unusual.)  Usually, SlashDecplaces is just the number of decimal 
  208.        places.  If it is 255, the series has not been compressed. 
  209.      NDif = the number of differences (= Number of observations - 1).
  210.      FirstObs = the first observation, as a four-byte integer.
  211.      Differences = the first differences of the series, as 2-byte integers.
  212.  
  213.     If a zero occurs in the series, it is indicated by 32767 in the 
  214. differences.  The following difference applies to the previous non-zero 
  215. number, not to the zero.  This practice was adopted because some banks have 
  216. series with numerous missing observations which appear as zeroes.  Also, 
  217. some banks consider quarterly series to be monthly series in which only 
  218. the end-of-quarter months have non-zero values.
  219.  
  220.     If it was not possible to compress the series, the format is:
  221.  
  222.    item                  size in bytes   C type
  223.    ==============================================================
  224.    BaseYear              1               unsigned char
  225.    FreqPeriod            1               unsigned char
  226.    255                   1               unsigned char
  227.    nobs                  2               int
  228.    Observations          4*nobs          float
  229.  
  230.     Note that the 255 in the third byte is the signal that the series is not 
  231. compressed.  The next two bytes represent the number of observations, and 
  232. then follow the observations as 4-byte floating point numbers.
  233.  
  234.  
  235.     The compressed form can represent a series as accurately as can an 18-
  236. foot-high graph printed with laser-printer resolution of 300 dots
  237. per inch. (All series in the US National Accounts or Industrial
  238. Production Indexes compress easily.  In the Blue Pages of the Survey of
  239. Current Business, however, nearly ten percent fail to compress.  In IMF
  240. data, the hyperinflation of many third-world countries produces series 
  241. which fail to compress.)
  242.  
  243.  
  244.  
  245.  
  246.    Hashed banks differ from compressed banks mainly in the organization
  247. of their index files.  With standard and compressed banks, G keeps the
  248. names  of the series in memory and simply does a linear search for a
  249. name each time one is requested.  In the hashed banks, the names are
  250. grouped into bins on the basis of a number calculated from the letters
  251. of the name.  When a name is requested, G calculates the number,
  252. locates the bin in which the name has been put, reads in the names in
  253. that bin, and does a linear search over only those names to find the
  254. desired series.  The size of compressed banks is limited by the
  255. requirement that the total number of characters in the names of all
  256. series must be less than 64,000.  In practice, that limit translates to
  257. about six or seven thousand series.  Hashed banks, in contrast, can go
  258. up to several million series.  The effective constraint becomes the
  259. size of the user's hard disk.  The data file has the extension "hbk";
  260. and the index, "hin". 
  261.  
  262. The precise form of the hashed bank .hin and .hbk files is as follows:
  263.  
  264. The ".hin" file contains:
  265.    item                      size in bytes           C type
  266.    ==============================================================
  267.    ns                        4                       long
  268.    nbins                     2                       unsigned
  269.    nsb                       2*nbins                 unsigned
  270.    ncharb                    2*nbins                 unsigned
  271.    posbin                    4*nbins                 unsigned
  272.    binname(0)                nchar[0]                char
  273.    binposts(0)               4*nnmsb[0]              long
  274.    binname(1)                nchar[1]                char
  275.    binposts(1)               4*nnmsb[1]              long
  276.    binname(2)                nchar[2]                char
  277.    binposts(2)               4*nnmsb[2]              long
  278.    .
  279.    .
  280.    binname(nbins-1)          nchar[nbins-1]          char
  281.    binposts(nbins-1)         4*nnmsb[nbins-1]        long
  282.  
  283.    Here, ns denotes the number of series in the bank.  The series are 
  284.    separated into "bins".  The number of bins in the bank is denoted by 
  285.    nbins.  The number of series in each bin is denoted by the array nsb.  
  286.    The sum of the number of characters in the names (including each '\0') 
  287.    of the series contained in each bin is denoted by the array ncharb.  
  288.    The beginning positions in the ".hin" file of the first bytes of the 
  289.    binname() strings is given by the array posbin.  The string binname(i) 
  290.    denotes the concatination (including the \0's) of all the series names 
  291.    in the i-th bin.  Finally, binposts(i) denotes the array of beginning 
  292.    positions in the associated ".hbk" of the series in the the i-th bin.  
  293.    Of course, the ordering of the series in the binname() and binposts() 
  294.    arrays must be the same.
  295.  
  296.    Consider an example.  Suppose that the 3rd bin contains the series 
  297.    "joe", "dave", and "bill".  The string binname(3) would be
  298.  
  299.             "joe\0dave\0bill\0"  
  300.             
  301.    Suppose that the starting positions in the ".hbk" bank for the three  
  302.    series are 40700008, 490987, 3378294.  The array binposts(3) would then
  303.    be [40700008, 490987, 3378294].  And nsb[3] = 3, and ncharb[3] = 14.
  304.    If the beginning position of binname(3) in the ".hin" file is 4724, then
  305.    posbin[3] = 4724.
  306.  
  307.    To assign a bin number to a series you must use the following hashing
  308.    routine.  In C, the routine is:
  309.  
  310.    unsigned hash(char *s);
  311.  
  312.    hash(char *s)
  313.    {
  314.       unsigned bill;
  315.  
  316.       for (bill=0;*s!='\0';s++) bill = *s + 31*bill;
  317.       bill = bill%nbins;
  318.       return(bill);
  319.       }
  320.  
  321.    To continue with the example, to determine the bin which the series "joe"  
  322.    really belongs to you'd evaluate the  function hash("joe").
  323.  
  324. The .hbk file:
  325.     0 - 79           char       Name of bank (terminated with a null)
  326.     80 - 81          int        ns, number of series in the bank
  327.     82 - 85          long       psn, position in file of index
  328.     86 -                        first series, as described below
  329.     *(psn+1) -                  second series,
  330.     ...                         ...
  331.     psn              long       position in file of first byte of first series
  332.     psn+4            long       position in file of first byte of second series
  333.     ...                         ... on out to ns series
  334.  
  335. For each series, the format is:
  336.         byte    Content
  337.         0        base year
  338.         1        frequency*16+period
  339.         2        slash*16+maxplaces or 255 if not compressed
  340.         3-4        number of observations
  341.         5-8        first observation as a long
  342.         9 -        differences as integers
  343.         if not compressed, floats begin in byte 5    
  344.